package com.ttj.controller.godown_keeper;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ttj.domain.oracle.OrderInstock;
import com.ttj.domain.oracle.OrderInstockDetail;
import com.ttj.mapper.oracle.OrderInstockMapper;
import com.ttj.service.GoDownKeeperService;
import com.ttj.vo.BaseRes;


/**
 * 库管
 */
@Controller
@RequestMapping("godownKeeper")
public class GodownKeeperController {
	
	@Resource
	private GoDownKeeperService mGoDownKeeperService;
	@Resource
	private OrderInstockMapper mOrderInstockMapper;
	/**
	 * 用于展示输出结果，查看从后台传至前端的json是否正确
	 */
	@RequestMapping(value = "/showtest", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<OrderInstock> showProvince(String orderId) {
		return null;
	}
	/**
	 * 用于展示库管首页总计数量
	 */
	@RequestMapping(value = "/showhome", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<OrderInstock> showHome() {
		return mGoDownKeeperService.getUncheckedCount();
	}
	/**
	 * 用于展示收购员未验收、已验收、挂起列表
	 */
	@RequestMapping(value = "/showpurchaserList", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<Map> showPurchaserList() {
		return mGoDownKeeperService.showPurchaserList();
	}
	/**
	 * 用于展示收购员订单详情
	 */
	@RequestMapping(value = "/showpurchaserDetailByorderId", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<OrderInstock> showPurchaserDetailByorderId(String orderId) {
		return mGoDownKeeperService.showPurchaserDetail(orderId);
	}
	/**
	 * 未验收订单的挂起功能
	 */
	@RequestMapping(value = "/hangingOrderInstock", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<OrderInstock> hangingOrderInstock(String orderId) {
		return mGoDownKeeperService.hangingOrderInstock(orderId);
	}
	/**
	 * 未验收订单的验收功能
	 */
	@RequestMapping(value = "/checkOrderInstock", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<OrderInstock> checkOrderInstock(String orderId, String getDetail) {
		Gson gson = new Gson();
		Type listType = new TypeToken<List<OrderInstockDetail>>(){}.getType();
		List<OrderInstockDetail> fromJson = gson.fromJson(getDetail,listType);
		return mGoDownKeeperService.checkOrderInstock(orderId,fromJson);
	}
	
	/**
	 * 用于展示收购员未验收、已验收、挂起列表
	 */
	@RequestMapping(value = "/showserviceList", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<Map> showServiceList() {
		return mGoDownKeeperService.showServiceList();
	}
	
	/**
	 * 用于展示服务组订单详情
	 */
	@RequestMapping(value = "/showserviceDetailByorderId", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<OrderInstock> showServiceDetailByorderId(String orderId) {
		return mGoDownKeeperService.showServiceDetail(orderId);
	}
	
	/**
	 * 用于展示库管工作日志
	 */
	@RequestMapping(value = "/showKeeperDailyLog", method = RequestMethod.GET)
	@ResponseBody
	public BaseRes<Map> showKeeperDailyLog(String searchTimeType,String workerType,String startDate,String endDate) {
		return mGoDownKeeperService.showKeeperDailyLog(searchTimeType, workerType, startDate, endDate);
	}
}
